package com.zoe.onelink.logging.trace.dubbo;

import brave.internal.Nullable;
import brave.rpc.RpcClientResponse;
import cn.hutool.core.lang.Assert;
import org.apache.dubbo.rpc.Result;

public final class DubboClientResponse extends RpcClientResponse implements DubboResponse {
    final DubboClientRequest request;
    @Nullable
    final Result result;
    @Nullable
    final Throwable error;

    DubboClientResponse(
            DubboClientRequest request, @Nullable Result result, @Nullable Throwable error) {
        Assert.notNull(request);
        this.request = request;
        this.result = result;
        this.error = error;
    }

    @Override
    public Result result() {
        return result;
    }

    @Override
    public Result unwrap() {
        return result;
    }

    @Override
    public DubboClientRequest request() {
        return request;
    }

    @Override
    public Throwable error() {
        return error;
    }

    @Override
    public String errorCode() {
        return DubboParser.errorCode(error);
    }
}
